package com.ss.android.action.a.b;

import android.content.Context;
import android.os.Handler;
import android.os.Message;

import com.bytedance.article.common.c.TTUtils;
import com.bytedance.common.utility.Logger;
import com.ss.android.account.Spipe;
import com.ss.android.action.a.a.Comment;
import com.ss.android.common.AbsApiThread;
import com.ss.android.common.util.NetworkUtils;
import com.ss.android.http.legacy.a.NameValueImpl;
import com.ss.android.model.AbsArticle;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.json.JSONObject;

public final class a extends AbsApiThread {
    public long a;
    public int read_pct;
    public long staytime_ms;
    public boolean d;
    private String e;
    private String text;
    private String action;
    private boolean h;
    private int i;
    private long replay_to_comment_id;
    private long k;
    private AbsArticle mAbsArticle;
    private Handler mHandler;
    private Context mContext;

    public a(Context context, Handler handler, List arg7, String arg8, AbsArticle arg9, long arg10, String arg12, boolean arg13, int arg14, long arg15) {
        this.read_pct = -1;
        this.staytime_ms = -1;
        this.mHandler = handler;
        this.mContext = context.getApplicationContext();
        StringBuilder v2 = new StringBuilder();
        if(arg7 != null) {
            Iterator v3 = arg7.iterator();
            int v1;
            for(v1 = 1; v3.hasNext(); v1 = 0) {
                Object v0 = v3.next();
                if(v1 == 0) {
                    v2.append(",");
                }

                v2.append(((String)v0));
            }
        }

        this.e = v2.toString();
        this.action = arg12;
        this.text = arg8;
        this.h = arg13;
        this.i = arg14;
        this.replay_to_comment_id = arg15;
        this.mAbsArticle = arg9;
        this.k = arg10;
    }

    public final void run() {
        Message message2;
        String v5;
        JSONObject v3_1;
        int v10 = 1010;
        int v1 = 108;
        long v8 = 0;
        String dataPostMessageUrl = Spipe.dataPostMessageUrl;
        ArrayList<NameValueImpl> params = new ArrayList();
        if(!android.support.design.a.isTextEmpty(this.e)) {
            params.add(new NameValueImpl("platform", this.e));
        }

        params.add(new NameValueImpl("group_id", String.valueOf(this.mAbsArticle.groupId)));
        params.add(new NameValueImpl("item_id", String.valueOf(this.mAbsArticle.itemId)));
        params.add(new NameValueImpl("aggr_type", String.valueOf(this.mAbsArticle.aggrType)));
        params.add(new NameValueImpl("forum_id", "0"));
        if(this.k > v8) {
            params.add(new NameValueImpl("ad_id", String.valueOf(this.k)));
        }

        if(!android.support.design.a.isTextEmpty(mAbsArticle.tag)) {
            params.add(new NameValueImpl("tag", mAbsArticle.tag));
        }

        if(!android.support.design.a.isTextEmpty(this.text)) {
            params.add(new NameValueImpl("text", this.text));
        }

        if(this.h) {
            params.add(new NameValueImpl("is_comment", "0"));
        }
        else {
            params.add(new NameValueImpl("is_comment", "1"));
        }

        if(v8 > v8) {
            params.add(new NameValueImpl("dongtai_comment_id", "0"));
        }

        if(!android.support.design.a.isTextEmpty(this.action)) {
            params.add(new NameValueImpl("action", this.action));
        }

        if(this.replay_to_comment_id > v8) {
            params.add(new NameValueImpl("reply_to_comment_id", String.valueOf(this.replay_to_comment_id)));
        }

        if(this.read_pct >= 0) {
            params.add(new NameValueImpl("read_pct", String.valueOf(this.read_pct)));
        }

        if(this.staytime_ms > -1) {
            params.add(new NameValueImpl("staytime_ms", String.valueOf(this.staytime_ms)));
        }

        if(this.d) {
            params.add(new NameValueImpl("zz", "1"));
        }

        int v0_1 = 18;
        try {
            dataPostMessageUrl = NetworkUtils.executePost(1024, dataPostMessageUrl, ((List)params));
            if(dataPostMessageUrl == null) {
            }else if(dataPostMessageUrl.length() == 0) {
            }else {
                v3_1 = new JSONObject(dataPostMessageUrl);
                String v4_1 = v3_1.getString("message");
                v5 = v3_1.optString("expired_platform", null);
                if (!"error".equals(v4_1)) {

                } else {
                    if (!"session_expired".equals(v3_1.getJSONObject("data").optString("name"))) {
                        Logger.e("snssdk", "post_message error: " + dataPostMessageUrl);
                    } else if (v5 != null) {
                        v0_1 = v1;
                    } else {
                        v0_1 = 105;
                    }
                    message2 = this.mHandler.obtainMessage(1010);
                    message2.arg1 = v0_1;
                    message2.arg2 = this.i;
                    message2.obj = v5;
                    this.mHandler.sendMessage(message2);
                    return;
                }
                if ("success".equals(v4_1)) {
                    JSONObject dataJo = v3_1.getJSONObject("data");
                    Comment comment = new Comment();
                    comment.initWithJO(dataJo);
                    if (comment.groupId <= v8) {
                        comment.groupId = this.mAbsArticle.groupId;
                    }

                    comment.itemKey = this.mAbsArticle.getItemKey();
                    Message message = this.mHandler.obtainMessage(1009, comment);
                    if (v5 != null) {
                        comment.t = v5;
                        message.arg1 = 108;
                    }
                    message.arg2 = this.i;
                    this.mHandler.sendMessage(message);
                    return;
                }
                Logger.e("snssdk", "post_message fail: " + dataPostMessageUrl);
            }
        } catch(Throwable throwable) {
            v0_1 = TTUtils.getErrorCode(this.mContext, throwable);
        }

        message2 = this.mHandler.obtainMessage(v10);
        message2.arg1 = v0_1;
        message2.arg2 = this.i;
        this.mHandler.sendMessage(message2);
    }
}

